package Studing;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @ClassName SychronizeExample
 * @Description: TODO
 * @Author hl
 * @Date 2020/5/28
 * @Version V1.0
 **/
public class SychronizeExample {
    public void func1() {
        synchronized (this) {
            for (int i = 0; i < 10; i++) {
                System.out.print(i + " ");
            }
        }
    }

    public synchronized void  fun2(){
        for(int i=0;i<10;i++){
            System.out.print("a"+i+" ");
        }
    }

    public static void main(String[] args) {
        SychronizeExample e1=new SychronizeExample();
        SychronizeExample e2=new SychronizeExample();
        ExecutorService executorService= Executors.newCachedThreadPool();
        executorService.execute(()->e1.func1());
        executorService.execute(()->e1.fun2());

    }
}
